import { triggers, obj } from './super.js'
import { operateUI } from '../scene/scene.js';

Object.values(operateUI).forEach(i => {
    i.interactive = true;
})

const { up, down, left, right, attack, jump } = operateUI;

function trapper(cb) {
    return function(e) {
        obj.before = {...obj};
        cb(e);
        triggers.forEach(trigger => {
            trigger(obj);
        })
    }
}

function simpleEvent(sprite, obj, key) {
    sprite.addListener('touchstart', trapper(e => {
        obj[key] = true;
    }))
    sprite.addListener('touchend', trapper(e => {
        obj[key] = false;
    }))
}

simpleEvent(left, obj, 'isLeft');
simpleEvent(right, obj, 'isRight');
simpleEvent(up, obj, 'isUp');
simpleEvent(down, obj, 'isBottom');
simpleEvent(attack, obj, 'isA');
simpleEvent(jump, obj, 'isD');